package flc.ast.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;

import com.blankj.utilcode.util.FragmentUtils;

import java.util.ArrayList;
import java.util.List;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.databinding.ActivityHouseCalculateBinding;
import flc.ast.fragment.house.HouseKind1Fragment;
import flc.ast.fragment.house.HouseKind2Fragment;
import flc.ast.fragment.house.HouseKind3Fragment;
import flc.ast.fragment.house.RateTableFragment;
import stark.common.basic.event.EventStatProxy;

public class HouseCalculateActivity extends BaseAc<ActivityHouseCalculateBinding> {

    private List<Fragment> mFragmentList;
    private HouseKind1Fragment kind1Fragment;
    private HouseKind2Fragment kind2Fragment;
    private HouseKind3Fragment kind3Fragment;
    private RateTableFragment rateTableFragment;

    @Override
    protected int onCreate() {
        return R.layout.activity_house_calculate;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(this, mDataBinding.event1Container);
        EventStatProxy.getInstance().statEvent5(this, mDataBinding.event5Container);

        mDataBinding.ivHouseCalculateBack.setOnClickListener(v -> onBackPressed());

        mDataBinding.tvHouseKind1.setOnClickListener(this);
        mDataBinding.tvHouseKind2.setOnClickListener(this);
        mDataBinding.tvHouseKind3.setOnClickListener(this);
        mDataBinding.tvInterestTable.setOnClickListener(this);

        mFragmentList = new ArrayList<>();
        kind1Fragment = new HouseKind1Fragment();
        kind2Fragment = new HouseKind2Fragment();
        kind3Fragment = new HouseKind3Fragment();
        rateTableFragment = new RateTableFragment();

        mFragmentList.add(kind1Fragment);
        mFragmentList.add(kind2Fragment);
        mFragmentList.add(kind3Fragment);
        mFragmentList.add(rateTableFragment);

        FragmentUtils.add(getSupportFragmentManager(), mFragmentList, R.id.fl_container, 0);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.tvHouseKind1://组合贷款
                clearSelection();
                mDataBinding.tvHouseKind1.setTextColor(Color.parseColor("#000000"));
                mDataBinding.tvHouseKind1.setBackgroundResource(R.drawable.timer_sel);
                FragmentUtils.showHide(0, mFragmentList);
                break;
            case R.id.tvHouseKind2://商业贷款
                clearSelection();
                mDataBinding.tvHouseKind2.setTextColor(Color.parseColor("#000000"));
                mDataBinding.tvHouseKind2.setBackgroundResource(R.drawable.timer_sel);
                FragmentUtils.showHide(1, mFragmentList);
                break;
            case R.id.tvHouseKind3://公积金贷款
                clearSelection();
                mDataBinding.tvHouseKind3.setTextColor(Color.parseColor("#000000"));
                mDataBinding.tvHouseKind3.setBackgroundResource(R.drawable.timer_sel);
                FragmentUtils.showHide(2, mFragmentList);
                break;
            case R.id.tvInterestTable://利率表
                clearSelection();
                mDataBinding.tvInterestTable.setTextColor(Color.parseColor("#000000"));
                mDataBinding.tvInterestTable.setBackgroundResource(R.drawable.timer_sel);
                FragmentUtils.showHide(3, mFragmentList);
                break;
        }
    }

    @Override
    protected void initData() {

    }

    private void clearSelection() {
        mDataBinding.tvHouseKind1.setTextColor(Color.parseColor("#B2C1CF"));
        mDataBinding.tvHouseKind1.setBackground(null);
        mDataBinding.tvHouseKind2.setTextColor(Color.parseColor("#B2C1CF"));
        mDataBinding.tvHouseKind2.setBackground(null);
        mDataBinding.tvHouseKind3.setTextColor(Color.parseColor("#B2C1CF"));
        mDataBinding.tvHouseKind3.setBackground(null);
        mDataBinding.tvInterestTable.setTextColor(Color.parseColor("#B2C1CF"));
        mDataBinding.tvInterestTable.setBackground(null);
    }

}